package com.oauth.service.global.beans;

import java.util.EnumSet;
import java.util.StringTokenizer;

public enum GlobalDataType {

	STATUS_UPDATE("status"), BIRTHDAY_NOTIFACTION("birthday"), FRIEND_REQUEST("friend_request"), FRIEND_SUGGESTION(
			"friend_suggestion");

	private String name;

	/**
	 * 
	 */
	private GlobalDataType(String name) {
		this.name = name;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns enum based on name.
	 * 
	 * @param name
	 * @return
	 */
	public static GlobalDataType getEnumByName(String name) {
		for (GlobalDataType dataType : GlobalDataType.values()) {
			if (dataType.getName().equals(name)) {
				return dataType;
			}
		}
		return null;
	}

	/**
	 * Parse enum from comma separated enum strings.
	 * 
	 * @param string
	 * @return
	 */
	public static EnumSet<GlobalDataType> getEnumSetByName(String string) {
		EnumSet<GlobalDataType> enumSet = EnumSet.noneOf(GlobalDataType.class);
		StringTokenizer st = new StringTokenizer(string, ",");
		while (st.hasMoreTokens()) {
			String type = st.nextToken();
			enumSet.add(GlobalDataType.getEnumByName(type));
		}
		return enumSet;
	}
}
